package com.tudou.top2.model
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	public class AdDataModel
	{
		
		private var $adIcon:Sprite;
		
		private var $adPict:Sprite;
		
		public var adLink:String;
		
		public var hasAd:Boolean;
		//是否加载完成
		public var isLoaded:Boolean = false;
		
		private const iconRight:int = 8;
		
		public function AdDataModel()
		{
			$adIcon = new Sprite();
			
			$adPict = new Sprite();
			
			
		}
		public function addToIcon(disp:DisplayObject):void
		{
			if(disp == null) return ;
			adIcon.addChild(disp);
			adIcon.x = KiliTop2.flashWidth - KiliTop2.iconWidth - iconRight;
			adIcon.y = KiliTop2.flashHeight - KiliTop2.iconHeight;
			
			adIcon.buttonMode = true;
			adIcon.useHandCursor = true;
			
			var icon:DisplayObject = adIcon.getChildAt(0);
			var iconMask:Sprite = new Sprite();
			iconMask.graphics.beginFill(0xff0000, 0);
			iconMask.graphics.drawRect(0, 0, KiliTop2.iconWidth, KiliTop2.iconHeight);
			adIcon.addChild(iconMask);
			adIcon.mask = iconMask;
			
			//Icon不加背景
//			adIcon.graphics.beginFill(0x000000, 0);
//			adIcon.graphics.drawRect(0, 0, KiliTop2.iconWidth, KiliTop2.iconHeight);
			
		}
		public function addToPict(disp:DisplayObject):void
		{
			if(disp == null) return ;
			adPict.addChild(disp);
			adPict.x = KiliTop2.flashWidth - KiliTop2.adBannerWidth;
			adPict.y = 0;
			
			adPict.buttonMode =  true;
			adPict.useHandCursor = true;
			
			var pict:DisplayObject = adPict.getChildAt(0);
			var pictMask:Sprite = new Sprite();
			pictMask.graphics.beginFill(0xff0000, 0);
			pictMask.graphics.drawRect(0, 0, KiliTop2.adBannerWidth, KiliTop2.adBannerHeight);
			adPict.addChild(pictMask);
			adPict.mask = pictMask;

			adPict.graphics.beginFill(0x000000, 1);
			adPict.graphics.drawRect(0, 0, KiliTop2.adBannerWidth, KiliTop2.adBannerHeight);

		}
		
		public function get adIcon():Sprite
		{
			check();
			return $adIcon;
		}
		public function set adIcon(s:Sprite):void
		{
			check();
			$adIcon = s;
		}
		
		public function get adPict():Sprite
		{
			check();
			return $adPict;
		}
		public function set adPict(s:Sprite):void
		{
			check();
			$adPict = s;
		}
		private function check():void
		{
			if(!hasAd) throw new Error("No ad!");
		}
	}
}